package com.home766.controller.shop;

import com.home766.dto.DictionaryDTO;
import com.home766.entity.Cases;
import com.home766.service.CasesService;
import com.home766.service.IDictionaryService;
import net.biz.Page;
import net.biz.Pageable;
import net.biz.controller.admin.BaseController;
import net.biz.entity.ProductCategory;
import net.biz.service.ProductCategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller("shopCasesController")
@RequestMapping("/shop/cases")
public class CasesController extends BaseController {
	@Resource(name="casesServiceImpl")
	private CasesService casesService;
	@Resource(name = "productCategoryServiceImpl")
	private ProductCategoryService productCategoryService;
	@Resource(name="dictionaryServiceImpl")
	private IDictionaryService iDictionaryService;
	/***
	 * 查看页面跳转
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/view")
	public String viewPage(Long id, HttpServletRequest request, ModelMap model){
		@SuppressWarnings("unused")
		Cases cases = casesService.getCases(id);
		model.addAttribute("cases",cases);
		return "/shop/case/case";
	}
	/***
	 * 更多案例
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/list")
	public String getShopCasesList(Cases cases, HttpServletRequest request, ModelMap model, Pageable pageable){
		//只查已发布
		cases.setIsRelease(true);
		Page<Cases> caseList = casesService.getShopCasesList(cases,pageable);
		List<ProductCategory> listPc = productCategoryService.findRoots();
		List<DictionaryDTO> dictionaryList = iDictionaryService.searchChildren(33L);
		model.addAttribute("caseList",caseList);
		model.addAttribute("listPc",listPc);
		model.addAttribute("dictionaryList",dictionaryList);
		model.addAttribute("cases",cases);
		return "/shop/case/list";
	}
}
